home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / rcdsplay.zip / GRAFED.PAS < prev    next >
Pascal/Delphi Source File  |  1991-05-25  |  52KB  |  1,233 lines

  1. {*************************************************************************
  2.  TITLE   : GRAFED
  3.  VERSION : 2.1
  4.  AUTHOR  : Roger Carlson (after GRAFED5, version 3.2 of M.Riebe and
  5.            R.Carlson written for the IBM CS9000 computer) 5/29/90
  6.  FUNCTION: This unit contains the GRAF routine for interactive display of
  7.            xy data.
  8.  INPUTS  : DATA - The xy data.  The first index identifies x(1) or y(2)
  9.                   and the second index specifies the data point.
  10.            FILENAME - Name of the data file.
  11.            MINX   - Minimum x value.
  12.            MAXX   - Maximum x value.
  13.            LOY    - Smallest y value.
  14.            HIY    - Largest y value.
  15.            NUMPTS - Number of data points.
  16.  NOTES   : 1. In Turbo Pascal the maximum size of any variable is 64KB.
  17.               To use the largest possible data array sizes, I've used
  18.               a single precision data array, which uses 23 bit (7-8digit)
  19.               precision.
  20.  CHANGES : 6/2/90 (1.1,RJC) - Added window selection.
  21.            6/3/90 (1.2,RJC) - Modified to change passed parameters to
  22.              include x max and min rather than first and last index.
  23.            6/4/90 (1.3,RJC) - Added parameter window at bottom of screen.
  24.            6/12/90 (1.4,RJC) -Added crosshair, ruler and several bells and
  25.                               whistles.
  26.            7/6/90 (1.5,RJC) - Started some bells and whistles.  Moved
  27.              CLRBOX to AXISLBL.
  28.            3/23/91 (1.6,RJC) -Increased the maximum data array size to
  29.              7000 and changed data array type to single precision.  Also
  30.              changed screen driver path to d:\tp to be consistent with
  31.              lab computer setup.
  32.            3/28/91 (1.7,RJC) -Added peak integration routine and completed
  33.              the moving average option.
  34.            5/2/91 (1.8,RJC) - Corrected text file dump procedure to include
  35.              data filtering.
  36.            5/3/91 (1.9,RJC) - Added linear transformation of axes,
  37.              wavelength/wavenumber conversion of x axis, and change of
  38.              axis labels.
  39.            5/9/91 (2.0,RJC) - Added postscript print screen procedure,
  40.              user defined window bounds, pan left, pan right, expand
  41.              horizontally, dos shell command, and crosshair trace mode.
  42.            5/23/91 (2.1,RJC) - Corrected an array range error when the
  43.              newmode flag was set (eg for a linear transform of x).  Added
  44.              min/max procedure and nonlinear transforms.
  45. *************************************************************************}
  46.  
  47. UNIT GRAFED;
  48.  
  49. {$I-} {Disable IO checking.}
  50.  
  51. INTERFACE
  52.  
  53.   USES IOFUNCS;      {version 1.7}
  54.  
  55.   CONST MAXPTS=7000; {Maximum # of data points.}
  56.  
  57.   TYPE DARRAY=ARRAY[1..2,1..MAXPTS] OF SINGLE;
  58.  
  59.   PROCEDURE GRAF(VAR DATA:DARRAY; FILENAME:STR20; MINX,MAXX,LOY,HIY:REAL;
  60.                  NUMPTS:INTEGER);
  61.  
  62. IMPLEMENTATION
  63.  
  64. USES CRT,GRAPH,DOS,
  65.      MATH,        {VERSION 1.3}
  66.      AXISLBL;     {VERSION 2.6}
  67.  
  68. PROCEDURE GRAF;
  69.  
  70. CONST
  71.   DRIVERS='d:\tp';    {location of device drivers}
  72.   SCRLEFT=100;        {plot starts SCRLEFT units from left edge}
  73.   SCRBOTTOM=58;       {bottom of plot SCRBOTTOM units from screen bottom}
  74.   SCRTOP=28;          {top of plot SCRTOP unit from screen top}
  75.   LINE1=3;            {first line for window at top of screen}
  76.   LINE2=13;           {second line for window at top of screen}
  77.  
  78. VAR
  79.   ASCII       : INTEGER;  {ordinal value of a key pressed}
  80.   BWBSC       : integer;  {bottom window boundary in screen coordinates}
  81.   BWBUC       : REAL;     {bottom window bound in user coordinates}
  82.   CHFLAG      : BOOLEAN;  {turns crosshair display on}
  83.   CHSENS      : INTEGER;  {crosshair movement sensitivity}
  84.   CHXUC,CHYUC : REAL;     {crosshair user coordinates}
  85.   CHXSC,CHYSC : INTEGER;  {crosshair screen coordinates}
  86.   DONEFLAG    : BOOLEAN;  {flag to bet out of program}
  87.   ELIPSFLAG   : BOOLEAN;  {flags circling of each point}
  88.   ERRCODE     : integer;  {error code}
  89.   FILTYPE,
  90.   FILDEGREE,
  91.   FILDERIV,
  92.   FILWIDTH    : INTEGER;  {filter parameters}
  93.   FIRST       : INTEGER;  {index of current first displayed point}
  94.   FRAME       : BOOLEAN;  {flags need to redraw frame}
  95.   GRAPHDRIVER : integer;  {graphics device ID number}
  96.   GRAPHMODE   : integer;  {mode for the graphics device}
  97.   HIXUC       : REAL;     {highest x user coordinate}
  98.   kbdbox      : viewporttype; {graphics window at bottom of screen}
  99.   LAST        : INTEGER;  {index of last point currently displayed}
  100.   LINEFLAG    : BOOLEAN;  {flags connecting of points with lines}
  101.   LINFLAG     : BOOLEAN;  {flag to indicate choice of movable line}
  102.   LINLEN      : INTEGER;  {length of line in number of pixels}
  103.   LINXSC,LINYSC: INTEGER; {line screen coordinates}
  104.   LINXUC,LINYUC: REAL;    {line user coordinates}
  105.   LOXUC       : REAL;     {lowest x value in user coordinates}
  106.   LWBIC       : INTEGER;  {lefg window boundary in index coordinates}
  107.   LWBSC       : integer;  {left window boundary in screen coordinates}
  108.   LWBUC       : REAL;     {left window boundary in user coordinate}
  109.   NEWMODE     : BOOLEAN;  {flags choice of a new display mode}
  110.   OLDBWBUC    : REAL;     {temporary bottom window bound in user coords}
  111.   OLDLWBUC    : REAL;     {temporary left window bound in user coords}
  112.   REDRAW      : BOOLEAN;  {flags need to redraw the screen plot}
  113.   RWBIC       : INTEGER;  {rigth window boundary in index coordinates}
  114.   RWBSC       : integer;  {right window boundary in screen coordinates}
  115.   RWBUC       : REAL;     {right window boundary in user coordinate}
  116.   SCANCODE    : INTEGER;  {extended code for a key pressed}
  117.   STEPSIZE    : INTEGER;  {size of increments between points}
  118.   THETA       : REAL;     {angle of live vs. horizontal (radians)}
  119.   TRACE       : BOOLEAN;  {flags crosshair trace mode}
  120.   TWBSC       : integer;  {top window boundary in screen coordinates}
  121.   TWBUC       : REAL;     {top window boundary in user coordinates}
  122.   titlebox    : viewporttype; {graphics window at top of screen}
  123.   WINDSENS    : INTEGER;  {window movement sensitivity}
  124.   XLABEL      : STR40;    {label for x axis}
  125.   YLABEL      : STR40;    {label for y axis}
  126.  
  127. {************************ Coordinate Transformations ********************}
  128. FUNCTION XCOORDSC(DATAPT:REAL):INTEGER; BEGIN
  129.   {Returns x value in screen coordinates corresponding to the user
  130.    value DATAPT by comparing it to the left and right window boundaries
  131.    in user coordinates.}
  132.   XCOORDSC:=ROUND((DATAPT-LWBUC)*((RWBSC-LWBSC)/(RWBUC-LWBUC))+LWBSC);
  133. END; {XCOORDSC}
  134.  
  135. FUNCTION XDATAVAL(INDEX:INTEGER):REAL;
  136.   {Returns x coordinate value in user specified units for a given index
  137.    with user specified slope and intercept incorporated.}
  138. BEGIN
  139.   IF (INDEX>=1) AND (INDEX<=NUMPTS) THEN XDATAVAL:=DATA[1,INDEX]
  140.   ELSE XDATAVAL:=(INDEX-1)*(DATA[1,NUMPTS]-DATA[1,1])/(NUMPTS-1)+DATA[1,1]
  141. END; {XDATAVAL}
  142.  
  143. FUNCTION YCOORDSC(DATAPT:REAL):INTEGER; BEGIN
  144.   {Returns y value in screen coordinates corresponding to the supplied
  145.    user coordinate of the current point by comparing it to the top and
  146.    bottom displayed user coordinates.}
  147.   YCOORDSC:=ROUND((DATAPT-BWBUC)*((TWBSC-BWBSC)/(TWBUC-BWBUC))+BWBSC);
  148. END; {YCOORDSC}
  149.  
  150. FUNCTION XCOORDUC(DATAPT:REAL):REAL; BEGIN
  151.   {Returns the x value in user coordinates corresponding to the supplied
  152.    screen coordinate of a point.}
  153.   XCOORDUC:=(DATAPT-LWBSC)*(RWBUC-LWBUC)/(RWBSC-LWBSC)+LWBUC;
  154.   END;
  155.  
  156. FUNCTION YCOORDUC(DATAPT:REAL):REAL; BEGIN
  157.   {Returns the y value in user coordinates corresponding to the suppied
  158.    screen coordinate of a point.}
  159.   YCOORDUC:=(DATAPT-BWBSC)*(TWBUC-BWBUC)/(TWBSC-BWBSC)+BWBUC;
  160.   END;
  161.  
  162. FUNCTION YDATAVAL(INDEX:INTEGER):REAL;
  163.   {Returns y coordinate value in specified units for a given index to
  164.    the data array.}
  165. VAR TEMPINDEX:INTEGER;
  166. BEGIN
  167.   IF INDEX>LAST THEN TEMPINDEX:=LAST
  168.   ELSE IF INDEX<FIRST THEN TEMPINDEX:=FIRST
  169.   ELSE TEMPINDEX:=INDEX;
  170.   IF TEMPINDEX<=1 THEN TEMPINDEX:=1;
  171.   IF TEMPINDEX>=NUMPTS THEN TEMPINDEX:=NUMPTS;
  172.   YDATAVAL:=DATA[2,TEMPINDEX];
  173. END; {YDATAVAL}
  174.  
  175. {********************* FUNCTION FILTER ***************************